using System.Collections;
using UnityEngine;

namespace PKGames
{
	[CreateAssetMenu(fileName = "WindowMoveFromRightTransition", menuName = "Window Transitions/PanToRight", order = 2)]
	public class PanToRightWindowTransition : WindowTransition
	{
		[Range(0.1f, 10f)]
		public float duration = 0.5f;

		[Header("Transition enter Settings")]
		public iTween.EaseType easeTypeEntering = iTween.EaseType.easeOutExpo;

		[Header("Transition exiting Settings")]
		public iTween.EaseType easeTypeExiting = iTween.EaseType.easeInExpo;

		public override IEnumerator BeginOpenWindowTransition(RectTransform targetTransform)
		{
			BeginLastWindowOpenTransition();
			BeginNextWindowOpenTransition(targetTransform);
			yield return null;
		}

		private void BeginLastWindowOpenTransition()
		{
			if (!(_lastWindow == null))
			{
				Vector3 position = _lastWindow.transform.position;
				float num = position.x - _lastWindow.GetComponent<RectTransform>().rect.width;
				Vector3 lossyScale = _lastWindow.transform.lossyScale;
				float num2 = num * lossyScale.x;
				GameObject gameObject = CreateTransitionHelper();
				float x = num2;
				Vector3 position2 = _lastWindow.transform.position;
				float y = position2.y;
				Vector3 position3 = _lastWindow.transform.position;
				Vector3 vector = new Vector3(x, y, position3.z);
				iTween.MoveTo(_lastWindow.gameObject, iTween.Hash("position", vector, "time", duration, "easetype", easeTypeEntering.ToString(), "islocal", false, "OnComplete", "FinishMotion", "oncompletetarget", gameObject));
			}
		}

		private GameObject CreateTransitionHelper()
		{
			GameObject gameObject = new GameObject();
			gameObject.name = "TransitionHelperObjectTo";
			PanToRightWindowTransitionMotionHelper panToRightWindowTransitionMotionHelper = gameObject.AddComponent<PanToRightWindowTransitionMotionHelper>();
			panToRightWindowTransitionMotionHelper.transition = this;
			return gameObject;
		}

		private void BeginNextWindowOpenTransition(RectTransform targetTransform)
		{
			Vector3 position = _nextWindow.transform.position;
			Rect rect = ((RectTransform)_nextWindow.transform).rect;
			Vector3 position2 = new Vector3(position.x - rect.width, position.y, position.z);
			_nextWindow.transform.position = position2;
			float num = 0f;
			GameObject gameObject = CreateTransitionHelper();
			num = ((RectTransform)_nextWindow.transform).rect.width;
			((RectTransform)_nextWindow.transform).offsetMax = new Vector2(num, 0f);
			((RectTransform)_nextWindow.transform).offsetMin = new Vector2(num, 0f);
			_nextWindow.WindowHolder.SetActive(value: true);
			iTween.MoveTo(_nextWindow.gameObject, iTween.Hash("position", targetTransform.position, "time", duration, "easetype", easeTypeEntering.ToString(), "islocal", false, "OnComplete", "FinishMotion", "oncompletetarget", gameObject));
		}

		public override IEnumerator BeginCloseWindowTransition(RectTransform targetTransform)
		{
			BeginLastWindowCloseTransition();
			BeginNextWindowCloseTransition(targetTransform);
			yield return null;
		}

		private void BeginLastWindowCloseTransition()
		{
			if (!(_lastWindow == null))
			{
				Vector3 position = _lastWindow.transform.position;
				float num = position.x + _lastWindow.GetComponent<RectTransform>().rect.width;
				Vector3 lossyScale = _lastWindow.transform.lossyScale;
				float num2 = num * lossyScale.x;
				GameObject gameObject = CreateTransitionHelper();
				float x = num2;
				Vector3 position2 = _lastWindow.transform.position;
				float y = position2.y;
				Vector3 position3 = _lastWindow.transform.position;
				Vector3 vector = new Vector3(x, y, position3.z);
				iTween.MoveTo(_lastWindow.gameObject, iTween.Hash("position", vector, "time", duration, "easetype", easeTypeEntering.ToString(), "islocal", false, "OnComplete", "FinishMotion", "oncompletetarget", gameObject));
			}
		}

		private void BeginNextWindowCloseTransition(RectTransform targetTransform)
		{
			if (!(_nextWindow == null))
			{
				float x = 0f - ((RectTransform)_nextWindow.transform).rect.width;
				((RectTransform)_nextWindow.transform).offsetMax = new Vector2(x, 0f);
				((RectTransform)_nextWindow.transform).offsetMin = new Vector2(x, 0f);
				GameObject gameObject = CreateTransitionHelper();
				_nextWindow.WindowHolder.SetActive(value: true);
				iTween.MoveTo(_nextWindow.gameObject, iTween.Hash("position", targetTransform.position, "time", duration, "easetype", easeTypeEntering.ToString(), "islocal", false, "OnComplete", "FinishMotion", "oncompletetarget", gameObject));
			}
		}
	}
}
